<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-outbound-edit" th:object="${outbound}">
            <input id="outboundId" name="outboundId" th:field="*{outboundId}"  type="hidden">
            <div class="form-group">	
                <label class="col-sm-3 control-label">出库日期：</label>
                <div class="col-sm-8">
                    <input id="outboundDate" name="outboundDate" th:field="*{outboundDate}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">物品名称：</label>
                <div class="col-sm-8">
					<select id="goodsId" name="goodsId" class="form-control select2-hidden-accessible" >
						<option th:each="goodsList:${goodsLists}" th:value="${goodsList.goodsId}" th:text="${goodsList.goodsName}" th:field="*{goodsId}"></option>
					</select>
				</div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">数量：</label>
                <div class="col-sm-8">
                    <input id="outboundNumber" name="outboundNumber" th:field="*{outboundNumber}" class="form-control" type="text" onkeyup="countMoney()">
                </div>
            </div>
           <!--  <div class="form-group">	
                <label class="col-sm-3 control-label">单价：</label>
                <div class="col-sm-8">
                    <input id="outboundPrice" name="outboundPrice" th:field="*{outboundPrice}" class="form-control" type="text" onkeyup="countMoney()">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">金额：</label>
                <div class="col-sm-8">
                    <input id="outboundMoney" name="outboundMoney" th:field="*{outboundMoney}" class="form-control" type="text" readonly="readonly">
                </div>
            </div> -->
            <div class="form-group">	
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input id="remark" name="remark" th:field="*{remark}" class="form-control" type="text">
                </div>
            </div>
			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script th:src="@{/ajax/libs/select/select2.js}"></script>
    <script type="text/javascript">
	    layui.use('laydate', function(){
			var laydate = layui.laydate;
			//执行一个laydate实例
			laydate.render({
				elem: '#outboundDate' //指定元素
			});
		});
	    
	    Date.prototype.Format = function (fmt) { 
	        var o = {
	            "M+": this.getMonth() + 1, //月份 
	            "d+": this.getDate(), //日 
	            "h+": this.getHours(), //小时 
	            "m+": this.getMinutes(), //分 
	            "s+": this.getSeconds(), //秒 
	            "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
	            "S": this.getMilliseconds() //毫秒 
	        };
	        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	        for (var k in o)
	        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	        	return fmt;
		} 
	    
		$("#form-outbound-edit").validate({
			rules:{
				outboundDate:{
					required:true,
				},
				outboundNumber:{
					required:true,
				},
			},
			submitHandler: function(form) {
				edit();
			}
		});
		
		function edit() {
			var outboundId = $("input[name='outboundId']").val();
	    	var outboundDate = $("input[name='outboundDate']").val();
	    	outboundDate = new Date(outboundDate).Format("yyyy-MM-dd hh:mm:ss");
	    	var goodsId = $.form.selectSelects("goodsId");
	    	var outboundNumber = $("input[name='outboundNumber']").val();
	    	var outboundPrice = $("input[name='outboundPrice']").val();
	    	var outboundMoney = $("input[name='outboundMoney']").val();
	    	var remark =  $("input[name='remark']").val();
	    	$.ajax({
	    		cache : true,
	    		type : "POST",
	    		url : ctx + "store/outbound/edit",
	    		data : {
	    			"outboundId":outboundId,
	    			"outboundDate": outboundDate,
	    			"goodsId": goodsId,
	    			"outboundNumber" : outboundNumber,
	    			"outboundPrice" : outboundPrice,
	    			"outboundMoney" : outboundMoney,
	    			"remark":remark
	    		},
	    		async : false,
	    		error : function(request) {
	    			$.modal.alertError("系统错误");
	    		},
	    		success : function(result) {
	    			if (result.code == web_status.SUCCESS) {
	                	$.operate.saveSuccess(result);
	                } else {
	                	$.modal.msgError(result.msg);
	                }
	    		}
	    	});
	    }
		
		function countMoney(){
	    	var outboundPrice = $("input[name='outboundPrice']").val();
	    	var outboundNumber = $("input[name='outboundNumber']").val();
	    	var accountMoneyInput =  document.getElementById("outboundMoney");
	    	accountMoneyInput.value = outboundPrice*outboundNumber;
	    	
	    }
		
		// h所有修改，光标默认定位在第1个输入框
		var oldVal=$('input:eq(1)').val();
		$('input:eq(1)').val("").focus().val(oldVal);
	</script>
</body>
</html>
